<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="lib/layui/css/layui.css" media="all" />
<style>
.layui-anim-upbit {
	width: 280px !important;
	left: 67px !important;
}

.df {
	height: 100%;
	display: inline-block;
	/* margin-top: 8px; */
}

.width-a {
	display: inline;
	width: 160px;
	height: 32px;
}

.width-b {
	width: 410px;
}

.layui-form-select {
	display: inline-block;
	width: 160px;
	position: relative;
	right: 4px;
}

.layui-form-checkbox {
	position: relative;
	top: 5px !important;
}

.width-c {
	display: inline-block;
	width: 345px;
	height: 38px;
	position: relative;
	top: 1px;
}

.width-d {
	display: inline-block;
	width: 415px;
	height: 38px
}

.layui-form-autocomplete {
	display: inline-block;
}

.layui-form-autocomplete-focus {
	position: relative;
	right: 346px;
	top: 18px;
}

.layui-anim {
	width: 347px;
}

.layui-form-label {
	line-height: 14px;
	height: 26px;
	width: 60px;
}

.layui-input {
	width: 130px;
	height: 38px;
}

.layui-form-select {
	width: 130px;
	margin-left: 2px;
}

.layui-inline {
	padding-top: 4px;
	line-height: 14px;
}
</style>
</head>
<body style="background-color: white; overflow-y: scroll;">
	<div style="width: 100%; height: 100%;">
			<input type="hidden" id="edit">
			<form class="layui-form" action="" id="f1" lay-filter="deliveryForm" >
				<div class="layui-inline">
					<label class="layui-form-label"> 派件员 </label>
					<div class="layui-inline">
						<select name="deliveryman_name" lay-verify="">
							<option value="">请选择</option>
						</select>
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label"> <span style="color: red;">
							运单编号 </span>
					</label>
					<div class="layui-inline">
						<input type="text" id="waybill_number" style="width: 280px;"
							name="waybill_number" placeholder="" autocomplete="off"
							lay-verify="required" class="layui-input width-d">
					</div>
				</div>
				<br>
				<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" id="submit" lay-submit
					lay-filter="add">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
			
		</div>
		<!-- 每一个页面都要设置scan_code， 并且需要传回到后台 -->
		<input type = "hidden" name = "scan_code" value="4," >
		<input  type = "hidden" name = "scan_type"  >
		<input type = "hidden" name = "id" >
		<!-- <input type = "hidden" name = "waybill_number" > -->
		<input type = "hidden" name = "express_type_id" >
		<input type = "hidden" name = "item_type_id" >
		<input type = "hidden" name = "sender_client" >
		<input type = "hidden" name = "deliveryr" >
		<input type = "hidden" name = "transport_method_id" > 
		<input type = "hidden" name = "payment_method_id" >
		<input type = "hidden" name = "send_network_id" >
		<input type = "hidden" name = "weight" >
<!-- 		<input type = "hidden" name = "deliveryman_id" >
 -->		<input type = "hidden" name = "taker_id" >
		<input type = "hidden" name = "scanner_id" >
		<input type = "hidden" name = "last_stop_id" >
		<input type = "hidden" name = "next_stop_id" >
		<input type = "hidden" name = "destination_id" >
		<input type = "hidden" name = "shift_id" >
		<input type = "hidden" name = "pouch_id" >
		<input type = "hidden" name = "car_id" >
		<input type = "hidden" name = "agent_id" >
		<input type = "hidden" name = "create_time" >
		<input type = "hidden" name = "update_time" >
		<input type = "hidden" name = "status" >
		<input type = "hidden" name = "scan_power" >
		<input type = "hidden" name = "destination_network_id" >
		<input type = "hidden" name = "scan_network_id" >
		
			</form>
			</div>
		
</body>
<script type="text/javascript" src="lib/layui/layui.js"></script>
<script>
	//Demo
	layui.use([ 'form','table', 'layer', 'laydate', 'jquery' ], function() {
		form = layui.form;
		var laydate = layui.laydate
		$ = layui.jquery;

		 var value = $("#edit").val();
		 console.log("全部数据: "+value);
			var edit = null;
			if (value.length != 0)
			 edit = JSON.parse($("#edit").val());
			 console.log(edit)
			 //该方法可以使用
			 form.val("deliveryForm",edit);
			 
			 $("[name='id']").val(edit.id);
			 $("[name='id']").attr('readonly',true);
			 $("[name='waybill_number']").val(edit.waybill_number);
			 $("[name='waybill_number']").attr('readonly',true);
			 //var scan_type_codes = edit.scan_type +"1,"; //将状态码放入状态码集合中
			 $("[name='scan_type']").val("4");
			 // $("[name='scan_type']").val(scan_type_codes);
			 
			 
			 $("[name='express_type_id']").val(edit.express_type_id);
			 $("[name='express_type_id']").attr('readonly',true);
			 $("[name='item_type_id']").val(edit.item_type_id);
			 $("[name='item_type_id']").attr('readonly',true);
			 $("[name='operation_date']").val(edit.operation_date);
			 $("[name='operation_date']").attr('readonly',true);
			 $("[name='sender_client']").val(edit.sender_client);
			 $("[name='sender_client']").attr('readonly',true);
			 $("[name='deliveryr']").val(edit.deliveryr);
			 $("[name='deliveryr']").attr('readonly',true);
			 $("[name='transport_method_id']").val(edit.transport_method_id);
			 $("[name='transport_method_id']").attr('readonly',true);
			 $("[name='payment_method_id']").val(edit.payment_method_id);
			 $("[name='payment_method_id']").attr('readonly',true);
			 $("[name='send_network_id']").val(edit.send_network_id);
			 $("[name='send_network_id']").attr('readonly',true);
			 $("[name='weight']").val(edit.weight);
			 $("[name='weight']").attr('readonly',true);
			 $("[name='deliveryman_id']").val(edit.deliveryman_id);
			 $("[name='deliveryman_id']").attr('readonly',true);
			 $("[name='taker_id']").val(edit.taker_id);
			 $("[name='taker_id']").attr('readonly',true);
			 $("[name='scanner_id']").val(edit.scanner_id);
			 $("[name='scanner_id']").attr('readonly',true);
			 $("[name='last_stop_id']").val(edit.last_stop_id);
			 $("[name='last_stop_id']").attr('readonly',true);
			 $("[name='next_stop_id']").val(edit.next_stop_id);
			 $("[name='next_stop_id']").attr('readonly',true);
			 $("[name='destination_id']").val(edit.destination_id);
			 $("[name='destination_id']").attr('readonly',true);
			 $("[name='shift_id']").val(edit.shift_id);
			 $("[name='shift_id']").attr('readonly',true);
			 $("[name='pouch_id']").val(edit.pouch_id);
			 $("[name='pouch_id']").attr('readonly',true);
			 $("[name='car_id']").val(edit.car_id);
			 $("[name='car_id']").attr('readonly',true);
			 $("[name='agent_id']").val(edit.agent_id);
			 $("[name='agent_id']").attr('readonly',true);
			 $("[name='create_time']").val(edit.create_time);
			 $("[name='create_time']").attr('readonly',true);
			 $("[name='update_time']").val(edit.update_time);
			 $("[name='update_time']").attr('readonly',true);
			 $("[name='status']").val(edit.status);
			 $("[name='status']").attr('readonly',true);
			 $("[name='scan_power']").val(edit.scan_power);
			 $("[name='scan_power']").attr('readonly',true);
			 $("[name='destination_network_id']").val(edit.destination_network_id);
			 $("[name='destination_network_id']").attr('readonly',true);
			 $("[name='scan_network_id']").val(edit.scan_network_id);
			 $("[name='scan_network_id']").attr('readonly',true);
			 $("[name='shipment_type_name']").val(edit.shipment_type_name);
			 $("[name='shipment_type_name']").attr('readonly',true);
			 $("[name='item_name']").val(edit.item_name);
			 $("[name='item_name']").attr('readonly',true);
			 $("[name='transport_method']").val(edit.transport_method);
			 $("[name='transport_method']").attr('readonly',true);
			 $("[name='destination_name']").val(edit.destination_name);
			 $("[name='destination_name']").attr('readonly',true);
			 $("[name='frequenct_name']").val(edit.frequenct_name);
			 $("[name='frequenct_name']").attr('readonly',true);
			 $("[name='car_number']").val(edit.car_number);
			 $("[name='car_number']").attr('readonly',true);
			 $("[name='next_stop_name']").val(edit.next_stop_name);
			 $("[name='next_stop_name']").attr('readonly',true);
			 $("[name='last_stop_name']").val(edit.last_stop_name);
			 $("[name='last_stop_name']").attr('readonly',true);
			 $("[name='scan_network_name']").val(edit.scan_network_name);
			 $("[name='scan_network_name']").attr('readonly',true);
			 $("[name='send_network_name']").val(edit.send_network_name);
			 $("[name='send_network_name']").attr('readonly',true);
			 $("[name='destination_network_name']").val(edit.destination_network_name);
			 $("[name='destination_network_name']").attr('readonly',true);
			 $("[name='take_name']").val(edit.take_name);
			 $("[name='take_name']").attr('readonly',true);
			 $("[name='scanner_name']").val(edit.scanner_name);
			 $("[name='scanner_name']").attr('readonly',true);
			 $("[name='deliveryman_name']").val(edit.deliveryman_name);
			 $("[name='deliveryman_name']").attr('readonly',true);
			 $("[name='agent_name']").val(edit.agent_name);
			 $("[name='agent_name']").attr('readonly',true);
			 // 暂时没有需求
			/*  $("[name='typeName']").val(edit.typeName);
			 $("[name='typeName']").attr('readonly',true);
			 $("[name='paymentType']").val(edit.paymentType);
			 $("[name='paymentType']").attr('readonly',true); */
			  $("[name='settment_method']").val(edit.typeName+"-"+edit.paymentType);
			 $("[name='settment_method']").attr('readonly',true); 
			// 

		laydate.render({
			elem : '#create_time',
			trigger : 'click',
			value : new Date()
			
		})

		
	
		
		//派件员下拉框的拼接
		$.get("api/emp?op=list", function(d) {
			if (d.code == 0) {
				for ( var idx in d.data) {
					$("[name = 'deliveryman_name']").append(
							"<option value='"+d.data[idx].staff_Id+"'>"
									+ d.data[idx].name + "</option>");

					$("[name = 'deliveryman_name']").next().children("dl").append(
							"<dd lay-value='"+d.data[idx].staff_Id+"' class>"
									+ d.data[idx].name + "</dd>")
				}

				form.render('select'); //渲染下拉组件
				if (edit != null) {
		 			form.val("deliveryForm",{
		 				"deliveryman_name": edit.staff_id
					}); 
		 			}
			} else {
				layer.msg(d.msg, {
					icon : 2
				});
			}

		})
		
		/*
		//运输方式下拉框的拼接
		$.get("api/tranportMethod?op=list", function(d) {
			if (d.code == 0) {
				for ( var idx in d.data) {
					$("[name = 'transport_method_id']").append(
							"<option value='"+d.data[idx].transport_method_id+"'>"
									+ d.data[idx].transport_method + "</option>");

					$("[name = 'transport_method_id']").next().children("dl").append(
							"<dd lay-value='"+d.data[idx].transport_method_id+"' class>"
									+ d.data[idx].transport_method + "</dd>")
				}

				form.render('select'); //渲染下拉组件
				if (edit != null) {
		 			form.val("deliveryForm",{
		 				"transport_method_id": edit.transport_method_id
					}); 
		 			}
			} else {
				layer.msg(d.msg, {
					icon : 2
				});
			}

		})
		
		//快件类型下拉框的拼接
		$.get("api/shipmenttype?op=list", function(d) {
			if (d.code == 0) {
				for ( var idx in d.data) {
					$("[name = 'express_type_id']").append(
							"<option value='"+d.data[idx].id+"'>"
									+ d.data[idx].shipment_type_name + "</option>");

					$("[name = 'express_type_id']").next().children("dl").append(
							"<dd lay-value='"+d.data[idx].id+"' class>"
									+ d.data[idx].shipment_type_name + "</dd>")
				}

				form.render('select'); //渲染下拉组件
				if (edit != null) {
		 			form.val("deliveryForm",{
		 				"express_type_id": edit.express_type_id

					}); 
		 			}
				
			} else {
				layer.msg(d.msg, {
					icon : 2
				});
			}

		})

		 
		//付款方式下拉框的拼接
		$.get("api/paymentMethod?op=list",
				function(d) {
					if (d.code == 0) {
						for ( var idx in d.data) {
							$("[name = 'settment_method']").append(
									"<option value='"+d.data[idx].id+"'>"
											+ d.data[idx].typeName + "=>"
											+ d.data[idx].paymentType
											+ "</option>");

							$("[name = 'settment_method']").next().children(
									"dl")
									.append(
											"<dd lay-value='"+d.data[idx].id+"' class>"
													+ d.data[idx].typeName
													+ "=>"
													+ d.data[idx].paymentType
													+ "</dd>")
						}

						form.render('select'); //渲染下拉组件
						if (edit != null) {
				 			 form.val("deliveryForm",{
				 				"settment_method": edit.settment_method
							});  
							
							$("[name = 'settment_method']").attr('readonly',true);
				 			}
						

					} else {
						layer.msg(d.msg, {
							icon : 2
						});
					}

				})
				*/

		//监听提交
		form.on('submit(add)', function(data) {
			var params = JSON.stringify(data.field);
			console.log("params:"+params);
			$.post('api/scan?op=save',data.field,function(d) {
				
				if (d.code == 200) {
					layer.msg(d.msg,{"icon":2});
				}
			})
			//renderdata(params)
			/* 
		  	 tableIns.reload({
		 		  
		 		    where : data.field
		 		  
		 		});   */
			return false;
		});

	});
	
	


</script>


</html>